package com.marvels.system.permission.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.Page;
import com.marvels.common.exception.MarvelsBusinessException;
import com.marvels.common.utils.MarvelsLogUtil;
import com.marvels.system.permission.dto.SysUserDTO;
import com.marvels.system.permission.dto.SysUserParamDTO;
import com.marvels.system.permission.service.SysUserService;

/**用户权限
 * @author 何杰
 * 2018年5月9日
 */
@RestController
@RequestMapping("/system/role/api")
public class SysUserApiController {
	@Autowired
	private SysUserService sysUserService;
	/**
	 * @author 何杰
	 * 2018年5月9日
	 * @return
	 */
	@RequestMapping("/querySysUser")
	@ResponseBody
	public SysUserDTO querySysUser(@RequestParam Integer userId){
		try {
			SysUserDTO dto = new SysUserDTO();
			dto.setUserId(userId);
			MarvelsLogUtil.getInstance().info("api_feign_querySysUser:"+dto);
			SysUserDTO sysUser = sysUserService.getUserById(dto);
			MarvelsLogUtil.getInstance().info("api_feign_query_SysUser:"+sysUser);
			return sysUser;
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error("marvels_FAIL...",e);
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("error...",e);
		}
		return null;
	}
	
	@RequestMapping("/querySysUserByUserCode")
	public SysUserDTO querySysUserByUserCode(@RequestParam String userCode){
		try { 
			MarvelsLogUtil.getInstance().info("api_feign_querySysUser_userCode:"+userCode);
			SysUserDTO sysUser = sysUserService.getUserByUserCode(userCode);
			MarvelsLogUtil.getInstance().info("api_feign_query_SysUser_userCode:"+sysUser);
			return sysUser;
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error("marvels_FAIL...",e);
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("error...",e);
		}
		return null;
	}
	/**
	 *获取所有用户信息 
	 * @return
	 */
	@RequestMapping("/querySysUserList")
	@ResponseBody
	public Page<SysUserDTO> querySysUserList(){
		try {
			Page<SysUserDTO> sysUserList = sysUserService.selectUserList();
			MarvelsLogUtil.getInstance().info("api_feign_query_sysUserList:"+sysUserList);
			return sysUserList;
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error("marvels_FAIL...",e);
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("error...",e);
		}
		return null;
	}
	
	
	
	/**
	 *获取用户列表信息 
	 * @return
	 */
	@RequestMapping("/querySysUsers")
	@ResponseBody
	public List<SysUserDTO> querySysUsers(@RequestBody SysUserParamDTO sysUserParamDTO){
		try {
			List<SysUserDTO> sysUserList = sysUserService.querySysUsers(sysUserParamDTO);
			MarvelsLogUtil.getInstance().info("api_feign_query_sysUserList:"+sysUserList);
			return sysUserList;
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error("marvels_FAIL...",e);
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("error...",e);
		}
		return null;
	}
	
	/**
	 * 
	 * 获取所有面签角色数量
	 */
	@RequestMapping("/selectUserByRoleCode")
	@ResponseBody
	public List<SysUserDTO> selectUserByRoleCode(@RequestParam("roleCode")String roleCode){
		try {
			List<SysUserDTO> sysUserList = sysUserService.selectUserByRoleCode(roleCode);
			MarvelsLogUtil.getInstance().info("api_feign_selectUserByRoleCode:"+sysUserList);
			return sysUserList;
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error("marvels_FAIL...",e);
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("error...",e);
		}
		return null;
	}
} 